import { api } from "@/lib/request";
import type { LoginResponseData, Response } from "@/types/response";
import type { LoginFormData } from "@/schemas/login";

// 登录API
export const loginAPI = {
  // 登录
  login: async (
    data: LoginFormData
  ): Promise<Response & { data: LoginResponseData }> => {
    // 对密码进行 base64 编码
    const encodedData = {
      ...data,
      password: btoa(data.password), // 使用 btoa 进行 base64 编码
    };
    const response = await api.post("/cas/login", encodedData);
    return response as unknown as Response & { data: LoginResponseData };
  },
};
